<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopSpell extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('shop_spell',['engine'=>'InnoDB'])->setComment('拼团团长表');
        $table->addColumn(Column::integer('uid')->setComment('团长用户id'));
        $table->addColumn(Column::integer('good_id')->setComment('商品id'));
        $table->addColumn(Column::integer('num')->setDefault(2)->setComment('成团人数'));
        $table->addColumn(Column::integer('join_num')->setDefault(0)->setComment('已加入人数'));
        $table->addColumn(Column::tinyInteger('status')->setDefault(0)->setComment('0待付款，1拼团中，2拼团成功，3拼团失败'));
        $table->addColumn(Column::dateTime('start_time')->setNullable()->setComment('拼团开始时间'));
        $table->addColumn(Column::dateTime('end_time')->setNullable()->setComment('拼团结束时间'));
        $table->addTimestamps('create_at');
        $table->create();
    }
}
